home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 51741 / 51741.xpi / chrome / content / lib / forms.js < prev    next >
Text File  |  2010-02-01  |  5KB  |  133 lines

  1. (function()
  2. {
  3.     //creates and shows a notification in all the tabs behind the tabbar
  4.     /*
  5.         example:
  6.             var buttons = [];
  7.             
  8.             var button = [];
  9.                 button[0] = 'Click to alert 1';
  10.                 button[1] = function(){alert('Cliked one!')}
  11.                 
  12.             buttons[buttons.length] = button;
  13.             
  14.             var button = [];
  15.                 button[0] = 'Click to alert 2';
  16.                 button[1] = function(){alert('Cliked two!')}
  17.                 
  18.             buttons[buttons.length] = button;
  19.             this.notifyTabs('This is the mensajitoooooooooooooooo o o o o ooooooo ', '', buttons, 4000);
  20.  
  21.     */
  22.     this.notifyTabs = function(aString, aType, anArrayButtons, aTime)
  23.     {
  24.         if(!anArrayButtons || anArrayButtons == '')
  25.             anArrayButtons = [];
  26.         var id = 'metaTitleDescriptionOnTop-notifyTabs-'+this.sha256(aString);
  27.         /*
  28.         var notification = this.getBrowserElement(id);
  29.         if(notification)
  30.         {
  31.             notification.setAttribute('hidden', false);
  32.             //hidding the notification
  33.             if(aTime)
  34.                 setTimeout(function(){notification.setAttribute('hidden', true);}, aTime);
  35.             return;
  36.         }*/
  37.         //the container
  38.         var hbox = this.create('hbox');
  39.             hbox.setAttribute('class', 'notification-inner outset');
  40.             hbox.setAttribute('style', 'max-width:100% !important;width:100% !important;');
  41.             hbox.setAttribute('id', id);
  42.         //the icon and the name of the extension
  43.         var toolbarbutton = this.create('toolbarbutton');
  44.             toolbarbutton.setAttribute('image', '');
  45.             toolbarbutton.setAttribute('label', "Meta Descripton & Title on Top : ");
  46.             toolbarbutton.setAttribute('style', 'border:1px solid transparent !important;margin:2px !important;padding:0px !important;-moz-appearance: none;margin-left:6px !important;');
  47.             hbox.appendChild(toolbarbutton);
  48.  
  49.         //the icon of the message
  50.         var toolbarbutton = this.create('toolbarbutton');
  51.             if(aType == 'warning')//warning image
  52.                 toolbarbutton.setAttribute('image', 'chrome://metaTitleDescriptionOnTop/content/lib/forms/notifyTabs/warning.png');
  53.             else if(aType == 'error')//error image
  54.                 toolbarbutton.setAttribute('image', 'chrome://metaTitleDescriptionOnTop/content/lib/forms/notifyTabs/error.png');
  55.             else//info image
  56.                 toolbarbutton.setAttribute('image', 'chrome://metaTitleDescriptionOnTop/content/lib/forms/notifyTabs/info.png');
  57.             //toolbarbutton.setAttribute('label', aString);
  58.             toolbarbutton.setAttribute('style', 'border:1px solid transparent !important;margin:0px !important;padding:0px !important;-moz-appearance: none;');
  59.             
  60.             hbox.appendChild(toolbarbutton);
  61.             
  62.         // the message to display
  63.             if(aString instanceof XULElement)
  64.             {
  65.                 var description = aString;
  66.                 var msgContainer = this.create('hbox');
  67.                     msgContainer.setAttribute("flex", '1');
  68.                     msgContainer.setAttribute("style", 'padding-top:3px;');
  69.                     msgContainer.appendChild(description)
  70.             }
  71.             else
  72.             {
  73.                 var description = this.create('description');
  74.                     description.appendChild(this.createText(aString));
  75.                     description.setAttribute("wrap", 'true');
  76.                 var msgContainer = this.create('vbox');
  77.                     msgContainer.setAttribute("flex", '1');
  78.                     msgContainer.setAttribute("style", 'padding-top:3px;');
  79.                     msgContainer.appendChild(description)
  80.             }
  81.             hbox.appendChild(msgContainer);
  82.         
  83.         
  84.         //the buttons
  85.         var defaultButton = false;
  86.         if(anArrayButtons)
  87.         {
  88.             for(var id in anArrayButtons)
  89.             {
  90.                 var toolbarbutton = this.create('button');
  91.                     toolbarbutton.setAttribute('label', anArrayButtons[id][0]);
  92.                     if(!defaultButton)
  93.                     {
  94.                         defaultButton = true;
  95.                         toolbarbutton.setAttribute('default', 'true');
  96.                     //    var focus = toolbarbutton;
  97.                     }
  98.                     toolbarbutton.setAttribute('oncommand', '('+anArrayButtons[id][1].toString()+')();metaTitleDescriptionOnTop.removeElement(this.parentNode)');
  99.                     toolbarbutton.setAttribute('style', 'font-size:11px;margin-bottom:0px !important;margin-top:0px !important;');
  100.                     hbox.appendChild(toolbarbutton);
  101.             }
  102.         }
  103.         //the close button
  104.         var toolbarbutton = this.create('toolbarbutton');
  105.         if(this.isSeaMonkey())
  106.         {
  107.             toolbarbutton.setAttribute('image', 'chrome://metaTitleDescriptionOnTop/content/lib/forms/notifyTabs/close-seamonkey.png');
  108.             toolbarbutton.setAttribute('style', 'border:1px solid transparent !important;margin:0px !important;padding:0px !important;-moz-appearance: none;margin-right:1px !important');
  109.         }
  110.         else
  111.         {
  112.             toolbarbutton.setAttribute('image', 'chrome://metaTitleDescriptionOnTop/content/lib/forms/notifyTabs/close-firefox.png');
  113.             toolbarbutton.setAttribute('style', 'border:1px solid transparent !important;margin:0px !important;padding:0px !important;-moz-appearance: none;margin-right:6px !important');
  114.         }
  115.         toolbarbutton.setAttribute('oncommand', 'metaTitleDescriptionOnTop.removeElement(this.parentNode)');
  116.         hbox.appendChild(toolbarbutton);
  117.         
  118.         //apppending the element to the tabbar
  119.         this.appendToTabbar(hbox);
  120.         //focusing the first button
  121.         //if(focus)
  122.         //    focus.focus();
  123.         //hidding the notification
  124.         if(aTime)
  125.             setTimeout(function(){hbox.setAttribute('hidden', true);}, aTime);
  126.         
  127.         return hbox;
  128.     }
  129.  
  130.     return null;
  131.  
  132. }).apply(metaTitleDescriptionOnTop);
  133.